package com.og.managedbean;

import java.io.Serializable;

import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import com.og.backingbean.Application;
import com.og.backingbean.ApplicationHistory;
import com.og.backingbean.Bug;
import com.og.backingbean.Company;
import com.og.backingbean.Composition;
import com.og.backingbean.Contract;
import com.og.backingbean.Module;
import com.og.backingbean.ModuleHistory;
import com.og.backingbean.Person;
import com.og.backingbean.Solution;
import com.og.backingbean.Status;
import com.og.backingbean.Ticket;
import com.og.backingbean.TimeSheet;
import com.og.backingbean.TimeSheetDate;
import com.og.backingbean.Type;
import com.og.dao.CRUDEntityDAO;

/**
 * @author Renaud DIANA
 *
 */
@Named
@SessionScoped
public class FindOneBean implements Serializable {

	private static final long serialVersionUID = 1L;

	/* Dependency injection */
	// Model
    @Inject
    CRUDEntityDAO<Application> applicationDAO;
    @Inject
    CRUDEntityDAO<ApplicationHistory> applicationHistoryDAO;    
    @Inject
    CRUDEntityDAO<Bug> bugDAO;
    @Inject
    CRUDEntityDAO<Company> companyDAO;
    @Inject
    CRUDEntityDAO<Composition> compositionDAO;
    @Inject
    CRUDEntityDAO<Contract> contractDAO;
    @Inject
    CRUDEntityDAO<Module> moduleDAO;
    @Inject
    CRUDEntityDAO<ModuleHistory> moduleHistoryDAO;
    @Inject
    CRUDEntityDAO<Person> personDAO;
    @Inject
    CRUDEntityDAO<Solution> solutionDAO;
    @Inject
    CRUDEntityDAO<Status> statusDAO;
    @Inject
    CRUDEntityDAO<Ticket> ticketDAO;
    @Inject
    CRUDEntityDAO<TimeSheet> timeSheetDAO;
    @Inject
    CRUDEntityDAO<TimeSheetDate> timeSheetDateDAO;
    @Inject
    CRUDEntityDAO<Type> typeDAO;
    
    // BackingBean
    @Inject
    Application application;    
    @Inject
    ApplicationHistory applicationHistory;
    @Inject
    Bug bug;
    @Inject
    Company company;    
    @Inject
    Composition composition;
    @Inject
    Contract contract;
    @Inject
    Module module;    
    @Inject
    ModuleHistory moduleHistory;
    @Inject
    Person person;
    @Inject
    Solution solution;    
    @Inject
    Status status;
    @Inject
    Ticket ticket;
    @Inject
    TimeSheet timeSheet;    
    @Inject
    TimeSheetDate timeSheetDate;
    @Inject
    Type type;
        
    /* -------------------- */
	
	/**
	 * Default constructor
	 */	
	public FindOneBean() {
		// TODO Auto-generated constructor stub
	}

	public String findOneApplication() {
				
		// Call model				
		application = applicationDAO.findOneEntity(application, application.getIdApplication());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find application Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneApplicationHistory() {
		
		// Call model				
		applicationHistory = applicationHistoryDAO.findOneEntity(applicationHistory, applicationHistory.getIdApplicationHistory());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find applicationHistory Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneBug() {
		
		// Call model				
		bug = bugDAO.findOneEntity(bug, bug.getIdBug());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find bug Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneCompany() {
				
		// Call model				
		company = companyDAO.findOneEntity(company, company.getIdCompany());
		
		// Populate person(s)
		person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find company Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneComposition() {
		
		// Call model				
		composition = compositionDAO.findOneEntity(composition, composition.getIdComposition());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find composition Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneContract() {
		
		// Call model				
		contract = contractDAO.findOneEntity(contract, contract.getIdContract());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find contract Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneModule() {
		
		// Call model				
		module = moduleDAO.findOneEntity(module, module.getIdModule());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find module Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findOneModuleHistory() {
	
		// Call model				
		moduleHistory = moduleHistoryDAO.findOneEntity(moduleHistory, moduleHistory.getIdModuleHistory());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find moduleHistory Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findOnePerson() {
		
		// Call model				
		person = personDAO.findOneEntity(person, person.getIdPerson());
		
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find person Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneSolution() {
		
		// Call model				
		solution = solutionDAO.findOneEntity(solution, solution.getIdSolution());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find solution Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findOneStatus() {
				
		// Call model				
		status = statusDAO.findOneEntity(status, status.getIdStatus());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find status Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneTicket() {
		
		// Call model				
		ticket = ticketDAO.findOneEntity(ticket, ticket.getIdTicket());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find ticket Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneTimeSheet() {
		
		// Call model				
		timeSheet = timeSheetDAO.findOneEntity(timeSheet, timeSheet.getIdTimeSheet());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find timeSheet Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}
	
	public String findOneTimeSheetDate() {
		
		// Call model				
		timeSheetDate = timeSheetDateDAO.findOneEntity(timeSheetDate, timeSheetDate.getIdTimeSheetDate());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find timeSheetDate Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	public String findOneType() {
				
		// Call model				
		type = typeDAO.findOneEntity(type, type.getIdType());
		
		// Populate person(s)
		//person = company.getListPersons().get(0);
						
		// Add message
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Find type Successful"));  
		
		// Navigation case
		return "";
		//return "success";
	}

	// Getters and Setters
	
	public Application getApplication() {
		return application;
	}

	public void setApplication(Application application) {
		this.application = application;
	}

	public ApplicationHistory getApplicationHistory() {
		return applicationHistory;
	}

	public void setApplicationHistory(ApplicationHistory applicationHistory) {
		this.applicationHistory = applicationHistory;
	}

	public Bug getBug() {
		return bug;
	}

	public void setBug(Bug bug) {
		this.bug = bug;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public Composition getComposition() {
		return composition;
	}

	public void setComposition(Composition composition) {
		this.composition = composition;
	}

	public Contract getContract() {
		return contract;
	}

	public void setContract(Contract contract) {
		this.contract = contract;
	}

	public Module getModule() {
		return module;
	}

	public void setModule(Module module) {
		this.module = module;
	}

	public ModuleHistory getModuleHistory() {
		return moduleHistory;
	}

	public void setModuleHistory(ModuleHistory moduleHistory) {
		this.moduleHistory = moduleHistory;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public Solution getSolution() {
		return solution;
	}

	public void setSolution(Solution solution) {
		this.solution = solution;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Ticket getTicket() {
		return ticket;
	}

	public void setTicket(Ticket ticket) {
		this.ticket = ticket;
	}

	public TimeSheet getTimeSheet() {
		return timeSheet;
	}

	public void setTimeSheet(TimeSheet timeSheet) {
		this.timeSheet = timeSheet;
	}

	public TimeSheetDate getTimeSheetDate() {
		return timeSheetDate;
	}

	public void setTimeSheetDate(TimeSheetDate timeSheetDate) {
		this.timeSheetDate = timeSheetDate;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}
	
}
